﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using GpsTagger.Logic;
using System.IO;

namespace GpsTagger.Tests
{
    public partial class PictureTaggerTestFrm : Form
    {
        public PictureTaggerTestFrm()
        {
            InitializeComponent();
        }

        private void PictureTaggerTestFrm_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            outputBox.Text = "";
            PictureTagger pt = new PictureTagger("exiftool.exe");
            ledTag.BackColor = Color.Red;
            if (pt.ValidTagger())
                ledTag.BackColor = Color.Green;
            ledRun.BackColor = Color.Red;
            if (pt.RunCommand(inputBox.Text))
            {
                ledRun.BackColor = Color.Green;
            }
            outputBox.Text = pt.GetLastOutput();            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void GenerateJpg_Click(object sender, EventArgs e)
        {
            {
                Bitmap genBmp = new Bitmap(500, 500);
                Graphics g = Graphics.FromImage(genBmp);
                SolidBrush sb = new SolidBrush(Color.Teal);
                g.FillRectangle(sb, new Rectangle(0, 0, genBmp.Width, genBmp.Height));
                genBmp.Save("output.jpg", ImageFormat.Jpeg);
            }
            PictureTagger pt = new PictureTagger("exiftool.exe");
            ledRun.BackColor = Color.Red;
            if (pt.RunCommand(" -listg0 output.jpg"))
            {
                ledRun.BackColor = Color.Green;
            }
            outputBox.Text = pt.GetLastOutput(); 
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            {
                Bitmap genBmp = new Bitmap(500, 500);
                Graphics g = Graphics.FromImage(genBmp);
                SolidBrush sb = new SolidBrush(Color.Teal);
                g.FillRectangle(sb, new Rectangle(0, 0, genBmp.Width, genBmp.Height));
                genBmp.Save("output.jpg", ImageFormat.Jpeg);
            }
            PictureTagger pt = new PictureTagger("exiftool.exe");

            long minTime = long.MaxValue;
            long maxTime = long.MinValue;
            long sumTime = 0;

            for(int x=-1;x<2;x+=2)
                for (int y = -1; y < 2; y += 2)
                {
                    outputBox.Text += "GUIDE: " + x + " " + y + Environment.NewLine;

                    MapPoint mp = new MapPoint("Coord 1", x*20, 30, 40, y*25, 35, 45);

                    ledRun.BackColor = Color.Red;
                    DateTime start = DateTime.Now;
                    DateTime end;
                    if (pt.TagPicture("output.jpg", mp, "(c) Mircea"))
                    {
                        end = DateTime.Now;
                        ledRun.BackColor = Color.Green;
                    }
                    else
                    {
                        end = DateTime.Now;
                    }
                    DateTime dt = new DateTime(end.Ticks - start.Ticks);
                    long current = dt.Second * 1000 + dt.Millisecond;
                    if (current < minTime) minTime = current;
                    if (current > maxTime) maxTime = current;
                    sumTime += current;

                    outputBox.Text += pt.GetLastOutput();
                    outputBox.Text += Environment.NewLine + "-------------------------------------------------" + Environment.NewLine;

                    ledTag.BackColor = Color.Red;
                    if (pt.RunCommand("-listg0 output.jpg"))
                    {
                        ledTag.BackColor = Color.Green;
                    }
                    outputBox.Text += pt.GetLastOutput();

                    outputBox.Text += Environment.NewLine + "-------------------------------------------------";
                    outputBox.Text += Environment.NewLine + "-------------------------------------------------" + Environment.NewLine;
                }
            sumTime /= 4;
            outputBox.Text += "Statistics : " + minTime + " " + sumTime + " " + maxTime;
        }
    }
}
